// https://ac.nowcoder.com/acm/problem/207040
#include <iostream>
using namespace std;
const int N = 1e5 + 10;
int a[N];
typedef long long LL;

int main()
{
    int n;
    cin >> n;
    LL sum = 0;
    for(int i = 1;i <= n;i++)
    {
        cin >> a[i];
        sum += a[i];
    }

    int left = 1, right = 1;
    LL ret = 0, k = 0;

    while(right <= n)
    {
        // 进窗口
        k += a[right];
        // 出窗口
        while(2 * k > sum)
        {
            // 用逆时针sum - k更新结果
            ret = max(ret, sum - k);
            k -= a[left++];
        }
        // 用顺时针k更新结果
        ret = max(ret, k);
        right++;
    }

    cout << ret << endl;
    return 0;
}